AO3-6783 Fix that removing a tag nomination would result in a blank tag nomination #4888
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
https://otwarchive.atlassian.net/browse/AO3-6783
Purpose
If a tag nomination is blank (empty string for tagname) because it is meant to be destroyed, don't modify it in
before_save
and exclude it from certain validations.Tag.find_by(name: "")
where name is an empty string returns the broken blank tag. Tag nominations that are meant to be removed have an empty string for the tag name. So,Tag.find_by_name(tagname)
in TagNomination'sbefore_save :set_tag_status
returns the broken blank tag and its name is used to set theTagNomination.tagname
. This means the nomination that was meant to be destroyed byafter_save :destroy_if_blank
is no longer blank, instead it contains all the information from the broken blank tag so it doesn't get destroyed. There is no way to get rid of this tag nomination, since any attempt to clear the tagname field will repeat this process. The only way to escape the broken blank tag is by renaming the nomination to a completely different tag name, but that still keeps the unwanted tag nomination around.The problem of the DB returning the broken tag also affects the autocomplete, so I've also added the bypass there.
While investigating which callbacks to skip, I noticed that
validate :known_fandom
on CastNomination would run for nominations about to be destroyed, so you needed to keep Fandom? filled out if you wanted to remove a character or relationship nomination in a tag set that doesn't allow fandom nominations. That's also fixed by skipping it for blank tagnames, so I went ahead and changed it.Testing Instructions
See Jira.
References
The database returning the zero width space tag when querying for an empty string is potentially caused by the database collation. However, the comments on AO3-6366 indicates that changing this collation would be a complicated endeavor. So this PR can serve as a workaround to get rid of the incredibly annoying behaviour currently happening on production until it's clear whether changing the collation fixes the underlying issue.
Note that all tests I added here (with the exception of
Scenario: Zero width space tag appears in the autocomplete for zero width space
) fail before the changes in this PR. So users on production are likely hitting the confusing "Someone else has already nominated the tag for this set but in fandom ...." error inScenario: A tag nomination with for the zero width space tag doesn't prevent removing other tag nominations
.Credit
Bilka (he/him)